<?php include (dirname(__FILE__)."/include/header.php"); ?>
<?php
	if(!empty($_POST['submit'])){
	$sql_2 = "select * from zy_user ";
	$result_2 = mysql_query($sql_2);
	while($rows=mysql_fetch_array($result_2)){
		$username=$_POST['username'];
		$password=$_POST['password'];
		$password1=$_POST['password1'];
		$mail=$_POST['mail'];
	if($mail==""){
		$error="Email不能为空";
	}else if($password==""){
		$error="密码不能为空";
	}else if($username==""){
		$error="昵称不能为空";
	}else if($rows['mail']==$mail){
		$error="Email重复";
	}else if($password != $password1){
		$error="两次密码不一致";
	}else if(empty($_POST['agreement'])){
	  $error="1";
	}
	}
	$sql1=mysql_query("select * from zy_user where mail='".$mail."'");
    $rows=mysql_fetch_array($sql1);
	if($username != null && $password == $password1 && $mail != null && $rows['mail']!=$mail){
		if($mail){             
			if (ereg("^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",$mail)){
				$sql="insert into zy_user(username,password,mail,integral,shop_id,remark,is_delete,create_user,create_time,update_user,update_time) values('$username','$password','$mail',0,0,'',0,'$username',now(),'username',now())";
			mysql_query($sql);
			$sql="SELECT a.user_id,a.username,a.password,a.mail,a.integral,a.shop_id,a.remark,a.is_delete AS user_is_delete ,a.create_user AS user_create_user ,a.create_time AS user_create_time,a.update_user AS user_update_user,a.update_time AS user_update_time ,b.*  FROM zy_user a LEFT JOIN zy_shop b ON a.shop_id=b.shop_id WHERE a.`mail`='".$mail."' AND PASSWORD='".$password."' LIMIT 0,1";
	$result = mysql_query($sql);
	if($rs = mysql_fetch_array($result)){              
			if($rs['shop_id']==0){          
			$_SESSION['_user']=$rs;
            unset($_SESSION['_shop']);
            	if($_REQUEST['gourl2']!=""){
			    
			if(strstr($_REQUEST['gourl2'],"user_login.php")){
					 echo "<script>location.href='index.php';</script>";
				}else{
			echo "<script>location.href='".$_REQUEST['gourl2']."'</script>";
				}
				}else{
                    echo "<script>location.href='index.php';</script>";
                }
			}else{
			$_SESSION['_shop']=$rs;  
			unset($_SESSION['_user']);         
			echo "<script>location.href='shop/shop_management.php';</script>";
			}
		}
			}else{
				$error="email格式不正确";
			}
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册</title>
</head>
<body>
<div class="container">
  <div class="loginpage">
    <div class="loginpage_img"></div>
    <div class="round_box login_box" >
      <div class="wht"></div>
      <div class="content">
        <div id="tab">
          <ul>
            <li class="login_link_off"><a href="<?php echo SITE_ROOT;?>/user_login.php"><span>会员登录</span></a></li>
            <li class="reg_link_on"><a href="<?php echo SITE_ROOT;?>/user_registration.php"><span>免费注册</span></a></li>
          </ul>
        </div>
        <div id="login_form_div" class="hidden"> </div>
        <div id="register_form_div">
          <form id="register_form" name="register" action="user_registration.php" method="post" onSubmit="return chkAgree();" >
	<input name="gourl2" value="<?php echo $_SERVER['HTTP_REFERER'];?>" type="hidden" />
		  <div class="field_line" ><font color="red"><?php echo $error;?></font></div>
            <div class="field_line mbt5"> <span class="red">*</span>Email</div>
            <div class="field_line mbt5">
              <input name="mail" type="text"  class="input_text" id="mail" value="<?php echo $mail;?>"/>
            </div>
            <div class="field_line mbt5"> <span class="red">*</span> 密码 (长度不能少于6位)</div>
            <div class="field_line mbt5">
              <input type="password" class="input_text" id="password" name="password" />
            </div>
            <div class="field_line mbt5"> <span class="red">*</span> 确认密码 </div>
            <div class="field_line mbt5">
              <input name="password1" type="password" class="input_text" id="password1" />
            </div>
            <div class="field_line mbt5"> <span class="red">*</span> 昵称 </div>
            <div class="field_line mbt5">
              <input name="username" type="text" class="input_text" id="username" value="<?php echo $username;?>"/>
            </div>
            <div class="field_line mbt5">
              <input type="hidden" value="<?php echo $_REQUEST['id'];?>" name="shop_id" />
              <input type="checkbox" id="agreement" checked="checked" name="agreement" />
              <input type='hidden' value='50113db0844e6' name='token' id="registerFormToken" />
              <span>我同意<a target="_blank" href="agreement.php" class="link">使用条款和协议</a></span> <span class="reg_button_wrapper">
              <input type="submit" title="" value="注册" id="submit" name="submit" post_click="提交中..." class="f14 btn w75 h30 btn-yellow yellow_h30_w75_p20" />
              </span> </div>
          </form>
        </div>
        <div class="cl"></div>
      </div>
    </div>
    <div class="clear"></div>
  </div>
  <a id="back-to-top" href="javascript:void(0);">
  <div class="backtotop"></div>
  </a> </div>
</div>
<script type="text/javascript" src="js/forward/public/foot.js"></script>
<script src="js/forward/public/sfGuardAuth.js"></script>
<script>
      window.onload = function () {
        var end_time = new Date().getTime();
        var load_time = end_time - start_time;
        _gaq.push(['_trackEvent', 'RenderTime', 'sfGuardAuth/register', '', load_time]);
      }
    </script>
<script type="text/javascript">
      var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
      document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F91e4a82e3fcc49680417f331c5d3bd8c' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    function chkAgree(){
    	if (document.register.password.value.length < 6){
    		alert ("密码不能少于6位");	
    		document.register.password.focus();
    		return false;
    	}
    	if(document.getElementById("agreement").checked){
    		  return true;
    		 }
    		 alert("请同意协议内容才能注册");
    		 return false;
    }
    </script>
<?php include (dirname(__FILE__)."/include/footer.php"); ?>
